# Generate kpoints on a sphere
import numpy as np
from numpy import pi, sin, cos

def inputparsing():
    from optparse import OptionParser

    parser = OptionParser()

    parser.add_option("--ntheta",action="store",type="int",default="25",help="[%default]")
    parser.add_option("--nphi",action="store",type="int",default="51",help="[%default]")
    parser.add_option("--k",action="store",type="float",default="0.02",help="[%default]")
    op,args=parser.parse_args()

    return op


if __name__=='__main__':

    op = inputparsing()
    th = np.linspace(0,pi/2,op.ntheta)
    ph = np.linspace(0,pi,op.nphi)

    theta,phi = np.meshgrid(th,ph)


    kx = sin(theta)*cos(phi)
    ky = sin(theta)*sin(phi)
    kz = cos(theta)

    k  = np.vstack((kx.flatten(),ky.flatten(),kz.flatten())).T

    np.savetxt('kfile.dat',k * op.k)
    
    np.savetxt('khatx.dat',kx)
    np.savetxt('khaty.dat',ky)
    np.savetxt('khatz.dat',kz)
    
